
package  com.superwindcloud
import scala.annotation.targetName
import scala.collection.mutable

sealed abstract private[superwindcloud] class SimpleBitSet {
  def contains(i: Int): Boolean
  def +=(i: Int): Unit
}

private[superwindcloud] object SimpleBitSet {

  def withSize(size: Int): SimpleBitSet = if (size <= 64) new Small else new Large(size)

  private class Small extends SimpleBitSet {
    private[this] var long: Long = _

    def contains(i: Int): Boolean = (long >> i & 0x1) != 0
    def +=(i: Int): Unit = long |= 0x1 << i
  }

  private class Large(size: Int) extends SimpleBitSet {
    private[this] val set = new mutable.BitSet(size)

    def contains(i: Int): Boolean = set.contains(i)
    def +=(i: Int): Unit = set += i
  }
}
 